import { LGXEnums } from "../common/sysenum";

class ShortCutKeySvc {
    constructor(canvas) {
        this.m_pCanvas = canvas;
    }

    onKeyPress(evt, mospos) {
        let flag = true;
        var keycode = evt.code;
        // console.log("main atc2 key---------------------")

        if (keycode == "Delete") {
            this.m_pCanvas.m_pEditINTF.delete();
        }
        else if (keycode == "Escape") {
            this.m_pCanvas.setMapWorkMode(LGXEnums.LGXWorkMode.ModifyMode);
        }
        else if (evt.ctrlKey && keycode == "KeyZ") {
            this.m_pCanvas.undo();
        }
        else if (evt.ctrlKey && keycode == "KeyY") {
            this.m_pCanvas.redo();
        }
        else if (evt.ctrlKey && keycode == "KeyC") {
            this.m_pCanvas.copy();
        }
        else if (evt.ctrlKey && keycode == "KeyV") {
            this.m_pCanvas.paste();
        }
        else if (evt.ctrlKey && keycode == "KeyA") {
            this.m_pCanvas.selectAll();
        }
        else if (evt.ctrlKey && evt.shiftKey && keycode == "KeyK") {
            var mapInfo = this.m_pCanvas.getDataManager().getMapViewInfo();
            if (!mapInfo.getDisScope()) {
                mapInfo.setDisScope(true);
            }
            else {
                mapInfo.setDisScope(false);
            }
        }
        else if (keycode == "ArrowLeft"
            || keycode == "ArrowRight"
            || keycode == "ArrowUp"
            || keycode == "ArrowDown") {
            if (this.m_pCanvas.getDataManager().getMapWorkMode() == LGXEnums.LGXWorkMode.WanderMode) {
                flag = false;
            }
            else {
                this.m_pCanvas.m_pEditINTF.arrowKeyTranslate(keycode);
            }
        }
        else {
            flag = false;
        }

        return flag;
    }

}

export default { ShortCutKeySvc }